#include "mainwindow.h"
#include "ui_mainwindow.h"
#include "math.h"
#include "QFile"
#include "QTextStream"

using namespace std;

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);
}

MainWindow::~MainWindow()
{
    delete ui;
}

void MainWindow::on_save_clicked()
{
    QFile file("settings.conf");
    file.open(QIODevice::ReadWrite|QIODevice::Text);
    QTextStream out(&file);

    out << "showdebug = ";
    out << ui->debug->isChecked();
    out << "(0, 1)" << endl;

    out << "console = ";
    out << ui->console->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_lightscattering = ";
    out << ui->scattering->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_hdr = ";
    out << ui->hdr->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_motionblur = ";
    out << ui->mblur->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_bloom = ";
    out << ui->bloom->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_shadows = ";
    out << QString::number((ui->shadowslider->value()*9)/100);
    out << "(2, 8)" << endl;

    out << "gfx_ssao = ";
    out << ui->ssao->isChecked();
    out << "(0, 1)" << endl;

    out << "gfx_antialiasing = ";
    out << QString::number((ui->aaslider->value()*5)/100);
    out << "(0, 4)" << endl;

    out << "resolution_width = ";
    out << ui->reswidth->text();
    out << "(320, 1600)" << endl;

    out << "resolution_height = ";
    out << ui->resheight->text();
    out << "(240, 1200)" << endl;

    out << "fullscreen = ";
    out << ui->fscreen->isChecked();
    out << "(0, 1)" << endl;

    out << "vsync = ";
    out << ui->vsync->isChecked();
    out << "(0, 1)" << endl;

    file.close();
}

void MainWindow::on_shadowslider_sliderMoved(int position)
{
    QString str = "ShadowDetail: ";
    str += QString::number((position*9)/100);
    ui->shadowlabel->setText(str);
}

void MainWindow::on_aaslider_sliderMoved(int position)
{
    QString str = "Antialiasing: ";
    int numb = pow(2,(position*5)/100);
    if(numb == 1)numb = 0;
    str += QString::number(numb);
    ui->aalabel->setText(str);
}
